;
(function (window, angular) {
    'use strict';
    angular.module("Controller.Stock.UnusualOut", [])
        .controller("UnusualOutCtrl", ["$scope", "$state", "ybWidget", "ybHttp", "MESG_TYPE", "$timeout", "EventBus", "$filter", "UserContextService", "$stateParams", function ($scope, $state, ybWidget, ybHttp, MESG_TYPE, $timeout, EventBus, $filter, UserContextService, $stateParams) {
            $scope.activeFlag = [true, false, false, false, false];
            $scope.datePickerFlag = [false, false];
            $scope.markInfo = {
                allCheckedBill: false,
                allCheckedMaterial: false,
                curRow: -1
            };
            $scope.pageInfo = {
                totalPages: 1,
                totalRows: 0,
                pageSize: 10,
                curPage: 1
            };
            $scope.submitted = false;
            $scope.condition = {};
            $scope.toolbarConfig = {
                showAdvanceSearch: false,
                showColConfig: false,
                showMateriel: false
            };
            $scope.dataList = [];
            $scope.outState = [
                {
                    id: 0,
                    name: "未出库"
                },
                {
                    id: 1,
                    name: "部分出库"
                },
                {
                    id: 2,
                    name: "已出库"
                },
                {
                    id: 3,
                    name: "强制结单"
                }
            ];
            $scope.reasonList = [];

            $scope.costPriceShow = false;

            $scope.tbConf = {
                fixedWidth: 400,
                scrollWidth: 1680,
                tableCol: [
                    {
                        type: "",
                        name: "申请单号",
                        dataField: "abnormalNo",
                        width: 180,
                        isShow: true,
                        isFixed: false,
                        clickFn: "viewDetail",
                        toSort: true,
                        sortType: ""
                    },
                    {
                        type: "",
                        name: "sap预留单号",
                        dataField: "sapOrder",
                        width: 180,
                        isShow: true,
                        isFixed: false,
                        toSort: true,
                        sortType: ""
                    },
                    {
                        type: "",
                        name: "零件凭证",
                        dataField: "voucherNo",
                        width: 150,
                        isShow: true,
                        isFixed: false,
                        toSort: true,
                        sortType: ""
                    },
                    {
                        type: "",
                        name: "产生原因",
                        dataField: "reasonName",
                        width: 100,
                        isShow: true,
                        isFixed: false,
                        toSort: true,
                        sortType: "",
                        isEN: true
                    },
                    {
                        type: "",
                        name: "客户",
                        dataField: "agentName",
                        width: 150,
                        isShow: true,
                        isFixed: false,
                        toSort: true,
                        sortType: ""
                    },
                    {
                        type: "",
                        name: "调出仓库",
                        dataField: "outLocation",
                        width: 100,
                        isShow: true,
                        isFixed: false,
                        toSort: true,
                        sortType: ""
                    },
                    {
                        type: "",
                        name: "制单人",
                        dataField: "createName",
                        width: 100,
                        isShow: true,
                        isFixed: false,
                        toSort: true,
                        sortType: ""
                    },
                    {
                        type: "",
                        name: "制单时间",
                        dataField: "applicationDateShow",
                        width: 100,
                        isShow: true,
                        isFixed: false,
                        toSort: true,
                        sortType: ""
                    },
                    {
                        type: "",
                        name: "出库状态",
                        dataField: "statusShow",
                        width: 100,
                        isShow: true,
                        isFixed: false,
                        toSort: true,
                        sortType: ""
                    },
                    {
                        type: "synSap",
                        name: "SAP同步状态",
                        dataField: "isSynsapSuccessShow",
                        width: 120,
                        isShow: true,
                        isFixed: false,
                        clickFn: "viewSapError",
                        toSort: true,
                        sortType: ""
                    },
                    {
                        type: "",
                        name: "过账状态",
                        dataField: "postingState",
                        width: 100,
                        isShow: true,
                        isFixed: false,
                        toSort: false,
                        sortType: ""
                    },
                    {
                        type: "",
                        name: "备注",
                        dataField: "note",
                        width: 150,
                        isShow: true,
                        isFixed: false,
                        toSort: true,
                        sortType: ""
                    },
                    {
                        type: "",
                        name: "CRM单号",
                        dataField: "crmOrder",
                        width: 150,
                        isShow: true,
                        isFixed: false,
                        toSort: true,
                        sortType: ""
                    },
                    {
                        type: "",
                        name: "总价",
                        dataField: "totalAmount",
                        width: 150,
                        isShow: true,
                        isFixed: false,
                        toSort: true,
                        sortType: ""
                    },
                    {
                        type: "",
                        name: "审核状态",
                        dataField: "auditStatusShow",
                        width: 120,
                        isShow: true,
                        isFixed: false,
                        toSort: false,
                        sortField: "",
                        sortType: ""
                    },
                    {
                        type: "",
                        name: "审核人",
                        dataField: "auditUserName",
                        width: 120,
                        isShow: true,
                        isFixed: false,
                        toSort: false,
                        sortField: "",
                        sortType: ""
                    },
                    {
                        type: "",
                        name: "审核时间",
                        dataField: "auditDateShow",
                        width: 160,
                        isShow: true,
                        isFixed: false,
                        toSort: false,
                        sortField: "",
                        sortType: ""
                    },
                    {
                        type: "",
                        name: "审核意见",
                        dataField: "auditRemark",
                        width: 120,
                        isShow: true,
                        isFixed: false,
                        toSort: false,
                        sortField: "",
                        sortType: ""
                    },
                    {
                        name: "回执状态",
                        dataField: "receiptStatusShow",
                        width: 120,
                        isShow: true,
                        isFixed: false,
                    },
                    {
                        type: "operate",
                        name: "操作",
                        dataField: "",
                        width: 360,
                        isShow: true,
                        isFixed: true,
                        toSort: false,
                        sortType: ""
                    }
                ]
            };

            $scope.newTbConf = {
                scrollWidth: 940,
                tableCol: [{
                        name: "零件编号",
                        width: 150,
                        dataField: "materialsNo",
                        input: false,
                        inputType: ""
                    },
                    {
                        name: "零件中文名",
                        width: 200,
                        dataField: "materialsDes",
                        input: false,
                        inputType: ""
                    },
                    {
                        name: "分类",
                        width: 150,
                        dataField: "materialsType",
                        input: false,
                        inputType: ""
                    },
                    {
                        name: "单位",
                        width: 120,
                        dataField: "unit",
                        input: false,
                        inputType: ""
                    },
                    {
                        name: "默认储位",
                        width: 180,
                        dataField: "stockLocation",
                        input: false,
                        inputType: ""
                    },
                    {
                        name: "实际库存",
                        width: 100,
                        dataField: "enableNum",
                        input: false,
                        clickFn: "alterReport",
                        inputType: ""
                    },
                    {
                        name: "出库数量",
                        width: 150,
                        dataField: "qty",
                        input: true,
                        inputType: "txt"
                    },
                    {
                        name: "意向占用",
                        dataField: "intentionNum",
                        width: 100,
                        input: false,
                        clickFn: "intentionDetail",
                        inputType: ""
                    },
                    {
                        name: "发货占用",
                        dataField: "deliveryNum",
                        width: 100,
                        input: false,
                        clickFn: "deliveryDetail",
                        inputType: ""
                    },
                    {
                        name: "单价",
                        width: 150,
                        dataField: "price",
                        input: true,
                        inputType: "price"
                    },
                    {
                        name: "总价",
                        width: 150,
                        dataField: "totalPrice",
                        input: false,
                        inputType: ""
                    },
                    {
                        name: "成本单价",
                        width: 150,
                        dataField: "costPrice",
                        input: false,
                        type: "cost",
                        inputType: ""
                    },
                    {
                        name: "成本小计",
                        width: 150,
                        dataField: "costSubtotal",
                        type: "cost",
                        input: false,
                        inputType: ""
                    }
                ]
            };
            $scope.editTbConf = {
                scrollWidth: 1280,
                tableCol: [{
                        name: "零件编号",
                        width: 150,
                        dataField: "materialsNo",
                        input: false,
                        inputType: ""
                    },
                    {
                        name: "零件中文名",
                        width: 200,
                        dataField: "materialsDes",
                        input: false,
                        inputType: ""
                    },
                    {
                        name: "分类",
                        width: 150,
                        dataField: "materialsType",
                        input: false,
                        inputType: ""
                    },
                    {
                        name: "单位",
                        width: 120,
                        dataField: "unit",
                        input: false,
                        inputType: ""
                    },
                    {
                        name: "默认储位",
                        width: 180,
                        dataField: "stockLocation",
                        input: false,
                        inputType: ""
                    },
                    {
                        name: "实际库存",
                        width: 120,
                        dataField: "enableNum",
                        clickFn: "alterReport",
                        input: false,
                        inputType: ""
                    },
                    {
                        name: "出库数量",
                        width: 150,
                        dataField: "qty",
                        input: true,
                        inputType: "txt"
                    },
                    {
                        name: "实际出库数量",
                        width: 110,
                        dataField: "realQty",
                        input: false,
                        inputType: ""
                    },
                    {
                        name: "出库状态",
                        width: 100,
                        dataField: "statusShow",
                        input: false,
                        inputType: ""
                    },
                    {
                        name: "意向占用",
                        dataField: "intentionNum",
                        width: 100,
                        input: false,
                        clickFn: "intentionDetail",
                        inputType: ""
                    },
                    {
                        name: "发货占用",
                        dataField: "deliveryNum",
                        width: 100,
                        input: false,
                        clickFn: "deliveryDetail",
                        inputType: ""
                    },
                    {
                        name: "单价",
                        width: 150,
                        dataField: "price",
                        input: true,
                        inputType: "price"
                    },
                    {
                        name: "总价",
                        width: 150,
                        dataField: "totalPrice",
                        input: false,
                        inputType: ""
                    },
                    {
                        name: "出库金额",
                        width: 150,
                        dataField: "outPrice",
                        input: false,
                        inputType: ""
                    },
                    {
                        name: "成本单价",
                        width: 150,
                        dataField: "costPrice",
                        input: false,
                        type: "cost",
                        inputType: ""
                    },
                    {
                        name: "成本小计",
                        width: 150,
                        dataField: "costSubtotal",
                        input: false,
                        type: "cost",
                        inputType: ""
                    },
                ]
            };
            $scope.viewTbConf = {
                scrollWidth: 1130,
                tableCol: [{
                        type: "",
                        name: "序号",
                        dataField: "rownum",
                        width: 80,
                        isShow: true,
                        isFixed: false,
                        toSort: false,
                        sortType: ""
                    },
                    {
                        name: "零件编号",
                        width: 150,
                        dataField: "materialsNo",
                        input: false,
                        inputType: ""
                    },
                    {
                        name: "零件中文名",
                        width: 200,
                        dataField: "materialsDes",
                        input: false,
                        inputType: ""
                    },
                    {
                        name: "分类",
                        width: 150,
                        dataField: "materialsType",
                        input: false,
                        inputType: ""
                    },
                    {
                        name: "单位",
                        width: 120,
                        dataField: "unit",
                        input: false,
                        inputType: ""
                    },
                    {
                        name: "默认储位",
                        width: 180,
                        dataField: "stockLocation",
                        input: false,
                        inputType: ""
                    },
                    {
                        name: "实际库存",
                        width: 120,
                        dataField: "enableNum",
                        input: false,
                        inputType: ""
                    },
                    {
                        name: "出库数量",
                        width: 120,
                        dataField: "qty",
                        input: true,
                        inputType: "txt"
                    },
                    {
                        name: "实际出库数量",
                        width: 120,
                        dataField: "realQty",
                        input: true,
                        inputType: "txt"
                    },
                    {
                        name: "已过账数量",
                        width: 120,
                        dataField: "postAmount",
                        input: false,
                        inputType: ""
                    },
                    {
                        name: "零件凭证",
                        width: 120,
                        dataField: "voucherNo",
                        input: false,
                        inputType: ""
                    },
                    {
                        name: "出库状态",
                        width: 150,
                        dataField: "statusShow",
                        input: true,
                        inputType: "txt"
                    },
                    {
                        name: "意向占用",
                        dataField: "intentionNum",
                        width: 100,
                        input: false,
                        clickFn: "intentionDetail",
                        inputType: ""
                    },
                    {
                        name: "发货占用",
                        dataField: "deliveryNum",
                        width: 100,
                        input: false,
                        clickFn: "deliveryDetail",
                        inputType: ""
                    },
                    {
                        name: "单价",
                        dataField: "price",
                        width: 100,
                        input: false,
                        inputType: ""
                    },
                    {
                        name: "总价",
                        dataField: "totalPrice",
                        width: 100,
                        input: false,
                        inputType: ""
                    },
                    {
                        name: "出库金额",
                        dataField: "outPrice",
                        width: 100,
                        input: false,
                        inputType: ""
                    },
                    {
                        name: "成本单价",
                        dataField: "costPrice",
                        width: 100,
                        input: false,
                        type: "cost",
                        inputType: ""
                    },
                    {
                        name: "成本小计",
                        dataField: "costSubtotal",
                        width: 100,
                        input: false,
                        type: "cost",
                        inputType: ""
                    },
                ]
            };
            $scope.outTbConf = {
                scrollWidth: 770,
                tableCol: [{
                        name: "零件编号",
                        width: 150,
                        dataField: "materialsNo",
                        input: false,
                        inputType: ""
                    },
                    {
                        name: "零件中文名",
                        width: 200,
                        dataField: "materialsDes",
                        input: false,
                        inputType: ""
                    },
                    {
                        name: "分类",
                        width: 150,
                        dataField: "materialsType",
                        input: false,
                        inputType: ""
                    },
                    {
                        name: "单位",
                        width: 120,
                        dataField: "unit",
                        input: false,
                        inputType: ""
                    },
                    {
                        name: "出库数量",
                        width: 150,
                        dataField: "qty",
                        input: false,
                        inputType: ""
                    },
                    {
                        name: "储位",
                        width: 150,
                        dataField: "locationCode",
                        input: true,
                        inputType: "func"
                    },
                    {
                        name: "出库状态",
                        width: 150,
                        dataField: "statusShow",
                        input: false,
                        inputType: ""
                    },
                    {
                        name: "意向占用",
                        dataField: "intentionNum",
                        width: 100,
                        input: false,
                        clickFn: "intentionDetail",
                        inputType: ""
                    },
                    {
                        name: "发货占用",
                        dataField: "deliveryNum",
                        width: 100,
                        input: false,
                        clickFn: "deliveryDetail",
                        inputType: ""
                    }
                ]
            };
            $scope.orderObj = {
                headerInfo: {},
                materialList: []
            };
            $scope.exportParam = {
                sectionUrl: ybHttp.RequestUrl("device", "/abnormalOut/export"),
                sectionParam: {
                    ids: []
                },
                allUrl: ybHttp.RequestUrl("device", "/abnormalOut/exportAll")
            };
            $scope.outTypeList = [];
            $scope.innerOrderList = [];
            $scope.innerOrder = {
                item: null
            };
            $scope.tabFlag = {};

            var btnPermissionCode = {
                unusualOutAdd: window.ActionCode.unusualOutAdd,
                unusualOutEdit: window.ActionCode.unusualOutEdit,
                unusualOutDel: window.ActionCode.unusualOutDel,
                unusualOutPrint: window.ActionCode.unusualOutPrint,
                unusualOutOut: window.ActionCode.unusualOutOut,
                unusualOutExport: window.ActionCode.unusualOutExport,
                unusualOutObligateAdd: window.ActionCode.unusualOutObligateAdd,
                unusualOutObligatePosting: window.ActionCode.unusualOutObligatePosting,
                mandatoryFinish: window.ActionCode.unusualOutMandatoryFinish,
                showCostPrice: window.ActionCode.showCostPrice,
                unusualOutTJSC: window.ActionCode.unusualOutTJSC,
                unusualOutAudit: window.ActionCode.unusualOutAudit,
            };

            $scope.btnPermission = {
                unusualOutAdd: true,
                unusualOutEdit: true,
                unusualOutDel: true,
                unusualOutPrint: true,
                unusualOutOut: true,
                unusualOutExport: true,
                unusualOutObligateAdd: true,
                unusualOutObligatePosting: true,
                mandatoryFinish: true,
                showCostPrice: true,
                unusualOutTJSC: true,
                unusualOutAudit: true,
            };

            function setBtnPermission() {
                for (var key in btnPermissionCode) {
                    $scope.btnPermission[key] = UserContextService.CheckPermission([btnPermissionCode[key]]);
                }
            }

            $scope.setFixedWidth = function () {
                $scope.tbStyle = {
                    fixedWidth: {
                        left: $scope.tbConf.fixedWidth + "px"
                    },
                    scrollLeftWidth: { width: $scope.tbConf.fixedWidth + "px" },
                };
            };

            $scope.changeTab = function (index) {
                $scope.activeFlag = [false, false, false, false, false];
                $scope.activeFlag[index] = true;
                $scope.submitted = false;
                switch (index) {
                    case 0:
                        initData();
                        break;
                    case 1:
                        if ($scope.outTypeList.length === 0) {
                            getTypeList();
                        }
                        break;
                    case 2:
                        if ($scope.outTypeList.length === 0) {
                            getTypeList();
                        }
                        break;
                    case 3:
                        break;
                    default:
                        break;
                }
            };

            function initData() {
                $scope.orderObj = {
                    headerInfo: {},
                    materialList: []
                };
                $scope.tabFlag = {};
                $scope.markInfo.allCheckedMaterial = false;
                $scope.toolbarConfig.showMateriel = false;
                $scope.innerOrderList = [];
                $scope.innerOrder = {
                    item: null
                };
            }

            function getDataList(curPage) {
                $scope.markInfo = {
                    allCheckedBill: false,
                    allCheckedMaterial: false,
                    curRow: -1
                };
                $scope.exportParam.sectionParam.ids = [];
                var service = "device";
                var reqUrl = "/abnormalOut/list";
                var param = {};
                param.pageSize = $scope.pageInfo.pageSize;
                if (!!curPage) {
                    $scope.pageInfo.curPage = curPage;
                }
                param.pageNum = $scope.pageInfo.curPage;
                param.filters = angular.copy($scope.condition);
                return ybHttp.Post(service, reqUrl, param).then(function (resp) {
                    if (resp.code !== 0) {
                        ybWidget.ShowMessage(resp, MESG_TYPE.Error);
                        return;
                    }
                    angular.forEach(resp.value.list, function (item) {
                        item.isChecked = false;
                        item.applicationDateShow = $filter("YbDate")(item.applicationDate, "yyyy-MM-dd HH:mm:ss");
                        item.statusShow = $filter("ProgressStatus")(item.status, "outDepot");
                        item.isSynsapSuccessShow = $filter("ProgressStatus")(item.isSynsapSuccess, "sap");
                        item.postingState = $filter("ProgressStatus")(item.postStatus, "posting");
                        item.auditStatusShow = $filter("AuditStatus2")(item.auditStatus);
                        item.auditDateShow = $filter("YbDate")(item.auditDate, "yyyy-MM-dd HH:mm:ss");
                        item.receiptStatusShow = $filter("ProgressStatus")(item.isReceipt, "receiptState");

                        item.syncCdglxtStatusShow = $filter("ProgressStatus")(item.syncCdglxtStatus, "synStatus");
                        item.syncCdglxtTimeShow = $filter("YbDate")(item.syncCdglxtTime, "yyyy-MM-dd HH:mm:ss");
                    });
                    $scope.pageInfo.totalRows = resp.value.total;
                    $scope.pageInfo.totalPages = resp.value.pages;
                    $scope.dataList = resp.value.list;
                    return resp.value.list
                });
            }

            $scope.selectRow = function (index) {
                $scope.markInfo.curRow = index
            };

            $scope.tdClick = function (item, fnType) {
                switch (fnType) {
                    case "viewDetail":
                        viewDetail(item);
                        break;
                    case "viewSapError":
                        viewSapError(item);
                        break;
                    case "alterReport":
                        alterReport(item);
                        break;
                    case "intentionDetail":
                        intentionDetail(item);
                        break;
                    case "deliveryDetail":
                        deliveryDetail(item);
                        break;
                    default:
                        break;
                }
            };

            function intentionDetail(item) {
                var param = {
                    materialsNo: item.materialsNo
                };
                ybWidget.IntentionDetail(param);
            }

            function deliveryDetail(item) {
                var param = {
                    materialsNo: item.materialsNo,
                    warehouseCode: $scope.orderObj.headerInfo.outLocation,
                    billNo: $scope.orderObj.headerInfo.abnormalNo
                };
                ybWidget.DeliveryDetail(param);
            }

            $scope.switchToolbar = function (toolbar) {
                if (!!$scope.toolbarConfig["show" + toolbar]) {
                    $scope.toolbarConfig["show" + toolbar] = false;
                } else {
                    $timeout(function () {
                        $scope.toolbarConfig["show" + toolbar] = true;
                    });
                }
            };

            $scope.switchDataPicker = function (index) {
                $scope.datePickerFlag = [false, false];
                if (angular.isDefined(index)) {
                    $scope.datePickerFlag[index] = true;
                }
            };

            $scope.checkDate = function (obj, startFiled, endFiled) {
                var timeFormatObj = ybWidget.CheckDate(obj[startFiled], obj[endFiled]);
                if (!!timeFormatObj.tStart) {
                    obj[startFiled] = timeFormatObj.tStart;
                }
                if (!!timeFormatObj.tEnd) {
                    obj[endFiled] = timeFormatObj.tEnd;
                }
            };

            $scope.search = function (curpage) {
                getDataList(curpage);
            };

            $scope.reset = function () {
                $scope.condition = {};
            };

            function getBillIds() {
                $scope.exportParam.sectionParam.ids = [];
                angular.forEach($scope.dataList, function (item) {
                    if (!!item.isChecked) {
                        $scope.exportParam.sectionParam.ids.push(item.id);
                    }
                });
            }

            $scope.selectSingle = function (item, list, type) {
                if (!item.isChecked) {
                    $scope.markInfo["allChecked" + type] = false;
                } else {
                    if (!checkAll(list)) {
                        $scope.markInfo["allChecked" + type] = false;
                    } else {
                        $scope.markInfo["allChecked" + type] = true;
                    }
                }
                getBillIds();
            };

            function checkAll(list) {
                var selectAll = false;
                for (var i = 0, len = list.length; i < len; i++) {
                    if (!list[i].isChecked) {
                        selectAll = false;
                        break;
                    }
                    selectAll = true;
                }
                return selectAll;
            }

            $scope.selectAll = function (list, type) {
                angular.forEach(list, function (item) {
                    item.isChecked = $scope.markInfo["allChecked" + type];
                });
                getBillIds();
            };

            $scope.applyOut = function () {
                $scope.tabFlag.type = 0;
                $scope.orderObj.headerInfo.createId = $scope.curUser.userId;
                $scope.orderObj.headerInfo.createName = $scope.curUser.name;
                $scope.orderObj.headerInfo.deptId = $scope.curUser.deptId;
                $scope.orderObj.headerInfo.dept = $scope.curUser.deptName;
                $scope.orderObj.headerInfo.applicationDate = +new Date();
                $scope.changeTab(1);
            };

            function getReason() {
                var service = "device";
                var reqUrl = "/dataDictionary/searchList";
                var reqParam = {};
                reqParam.parentCode = "OOFROMTYPE";
                ybHttp.Post(service, reqUrl, reqParam).then(function (resp) {
                    if (resp.code !== 0) {
                        ybWidget.ShowMessage(resp);
                        return;
                    }
                    $scope.reasonList = resp.value;
                });
            }

            function getTypeList() {
                var service = "device";
                var reqUrl = "/billTypeConfig/list";
                var param = {
                    filters: {
                        inOut: 1
                    },
                    pageNum: 0,
                    pageSize: 0
                };
                ybHttp.Post(service, reqUrl, param).then(function (resp) {
                    if (resp.code !== 0) {
                        ybWidget.ShowMessage(resp, MESG_TYPE.Error);
                        return false;
                    }
                    $scope.outTypeList = resp.value.list;
                })
            }

            function getInnerOrderList(billTypeId) {
                var service = "device";
                var reqUrl = "/billTypeConfig/item";
                var param = {};
                param.id = billTypeId;
                return ybHttp.Get(service, reqUrl, param).then(function (resp) {
                    if (resp.code !== 0) {
                        ybWidget.ShowMessage(resp, MESG_TYPE.Error);
                        return false;
                    }
                    return resp.value.detailList;
                });
            }

            $scope.changeBillType = function (billTypeId) {
                $scope.innerOrderList = [];
                $scope.innerOrder = {
                    item: null
                };
                getInnerOrderList(billTypeId).then(function (data) {
                    if (!data) {
                        return;
                    }
                    $scope.innerOrderList = data;
                });
            };

            $scope.delData = function (delType, billId) {
                var service = "device";
                var reqUrl = "/abnormalOut/remove";
                var billIds = [];
                if (delType === "single") {
                    billIds.push(billId);
                }
                if (delType === "batch") {
                    for (var i = 0, len = $scope.dataList.length; i < len; i++) {
                        if (!!$scope.dataList[i].isChecked) {
                            billIds.push($scope.dataList[i].id);
                        }
                    }
                }
                if (billIds.length === 0) {
                    ybWidget.ShowMessage('请选择需要删除的行');
                    return;
                }
                ybWidget.ShowMessage("确定要删除吗？", MESG_TYPE.Ask).then(function () {
                    ybHttp.Post(service, reqUrl, billIds).then(function (resp) {
                        if (resp.code !== 0) {
                            ybWidget.ShowMessage(resp, MESG_TYPE.Error);
                            return;
                        }
                        ybWidget.ShowToaster('success', '操作成功');
                        getDataList();
                    });
                });
            };

            $scope.selectWarehouse = function () {
                ybWidget.WarehouseUsingSelector({isUnUsualOut:true}).then(function (data) {
                    if (!!$scope.orderObj.headerInfo.outLocation && (data.warehouseCode !== $scope.orderObj.headerInfo.outLocation)) {
                        $scope.orderObj.headerInfo.outArea = "";
                        $scope.orderObj.headerInfo.sapOutArea = "";
                    }
                    $scope.orderObj.headerInfo.outLocation = data.warehouseCode;
                    // 实时更新库存数量
                    findDeliveryNum()
                })
            };

            $scope.clearWarehouse = function () {
                $scope.orderObj.headerInfo.outLocation = "";
                $scope.orderObj.headerInfo.outArea = "";
                $scope.orderObj.headerInfo.sapOutArea = "";
                // 实时更新库存数量
                findDeliveryNum()
            };

            $scope.selectArea = function () {
                if (!$scope.orderObj.headerInfo.outLocation) {
                    ybWidget.ShowToaster('error', '请选择调出仓库');
                    return;
                }
                var param = {};
                param.warehouseCode = $scope.orderObj.headerInfo.outLocation;
                ybWidget.DepotAreaSelector(param).then(function (data) {
                    $scope.orderObj.headerInfo.outArea = data.areaCode;
                    $scope.orderObj.headerInfo.sapOutArea = data.sapCode;
                    // 实时更新库存数量
                    findDeliveryNum()
                })
            };

            function alterReport(item) {
                var param = {
                    materialsNo: item.materialsNo
                };
                ybWidget.StorageReport(param);
            }

            $scope.clearArea = function () {
                $scope.orderObj.headerInfo.outArea = "";
                $scope.orderObj.headerInfo.sapOutArea = "";
                // 实时更新库存数量
                findDeliveryNum();
            };

            // 更新库存数量
            function findDeliveryNum() {
              if ($scope.orderObj.materialList.length <= 0) {
                return;
              }

              var service = "device";
              var reqUrl = "/materials/findDeliveryNum";
              var param = {};
              param.warehouseCode = $scope.orderObj.headerInfo.outLocation;
              param.areaCode = $scope.orderObj.headerInfo.outArea;
              param.materialsVOS = $scope.orderObj.materialList.map(item => ({materialsNo: item.materialsNo}))
              return ybHttp.Post(service, reqUrl, param).then(function (resp) {
                  console.log(resp.value);
                  if (resp.code !== 0) {
                      ybWidget.ShowMessage(resp, MESG_TYPE.Error);
                      return false;
                  }
                  if (!resp.value) {
                      return;
                  }
                  angular.forEach($scope.orderObj.materialList, function (item) {
                      angular.forEach(resp.value.materialsVOS, function (itemDetail) {
                          if (item.materialsNo === itemDetail.materialsNo) {
                              item.deliveryNum = itemDetail.deliveryNum;
                              item.enableNum = itemDetail.enableNum;
                            }
                      });
                  });
              }).catch(err => {
                console.log(err);
              });
            }

            $scope.selectLogisticsCom = function () {
                var param = {
                    name: "承运物流",
                    type: "carrier"
                };
                ybWidget.SingleSelector(param).then(function (data) {
                    $scope.orderObj.headerInfo.logistics = data.companyName;
                })
            };

            $scope.clearLogisticsCom = function () {
                $scope.orderObj.headerInfo.logistics = "";
            };

            $scope.selectAgent = function () {
                var param = {
                    name: "客户",
                    type: "dealer"
                };
                ybWidget.SingleSelector(param).then(function (data) {
                    $scope.orderObj.headerInfo.agentName = data.companyName;
                    $scope.orderObj.headerInfo.agentOrgId = data.dealerOrgId;
                })
            };

            $scope.clearAgent = function () {
                $scope.orderObj.headerInfo.agentName = "";
            };

            $scope.selMateriel = function (e) {
                if (!!$scope.toolbarConfig.showMateriel) {
                    e.stopPropagation();
                } else {
                    $timeout(function () {
                        $scope.toolbarConfig.showMateriel = true;
                        EventBus.Publish("getMaterial");
                    });
                }
            };

            $scope.importMateriel = function () {
                var param = {
                    name: "零件",
                    templateReqService: "device",
                    templateReqUrl: "/abnormalOut/download",
                    importReqService: "device",
                    importReqUrl: "/abnormalOut/import",
                    importErrorUrl: "",
                    warehouseCode: $scope.orderObj.headerInfo.outLocation,
                    areaCode: $scope.orderObj.headerInfo.outArea
                };
                ybWidget.ImportFile(param).then(function (data) {
                    angular.forEach(data, function (item) {
                        item.isChecked = false;
                    });
                    $scope.orderObj.materialList = [];
                    $scope.orderObj.materialList = angular.copy(data);
                });
            };

            $scope.delMateriel = function (item, index) {
                ybWidget.ShowMessage("确定要删除该记录吗？", MESG_TYPE.Ask).then(function () {
                    $scope.orderObj.materialList.splice(index, 1);
                    EventBus.Publish("setMaterial", item.materialsNo);
                });
            };

            $scope.batchDelMateriel = function () {
                var selectedCount = 0;
                for (var i = 0, len = $scope.orderObj.materialList.length; i < len; i++) {
                    if (!!$scope.orderObj.materialList[i].isChecked) {
                        selectedCount++;
                    }
                }
                if (!selectedCount) {
                    ybWidget.ShowMessage('请选择需要删除的行');
                    return;
                }
                ybWidget.ShowMessage("确定要删除选中的记录吗？", MESG_TYPE.Ask).then(function () {
                    for (var i = $scope.orderObj.materialList.length - 1; i >= 0; i--) {
                        if (!!$scope.orderObj.materialList[i].isChecked) {
                            $scope.orderObj.materialList.splice(i, 1);
                        }
                    }
                    if ($scope.orderObj.materialList.length === 0) {
                        $scope.markInfo.allCheckedMaterial = false;
                    }
                    EventBus.Publish("setMaterial");
                });
            };

            function getDetail(billId) {
                var service = "device";
                var reqUrl = "/abnormalOut/item";
                var param = {};
                param.id = billId;
                return ybHttp.Get(service, reqUrl, param).then(function (resp) {
                    if (resp.code !== 0) {
                        ybWidget.ShowMessage(resp, MESG_TYPE.Error);
                        return false;
                    }
                    angular.forEach(resp.value.materialList, function (item) {
                        item.statusShow = $filter("ProgressStatus")(item.status, "outDepot");
                        item.outPrice = $filter("decimalCover")(ybWidget.Times(item.realQty, item.price), 2);

                        checkItemStockStatus(item, +item.qty);
                    });
                    getInnerOrderList(resp.value.headerInfo.typeId).then(function (data) {
                        if (!data) {
                            return;
                        }
                        $scope.innerOrderList = data;
                    });

                    $scope.innerOrder = {
                        item: {
                            innerOrder: resp.value.headerInfo.innerOrder,
                            innerOrderNote: resp.value.headerInfo.innerOrderNote
                        }
                    };
                    return resp.value;
                });
            }

            function viewDetail(item) {
                getDetail(item.id).then(function (data) {
                    if (!data) {
                        return;
                    }
                    $scope.changeTab(3);
                    $scope.orderObj = data;
                });
            }

            function viewSapError(item) {
                ybWidget.ShowMessage(item.sapErrorMsg, MESG_TYPE.Note);
            }

            $scope.editData = function (item) {
                getDetail(item.id).then(function (data) {
                    if (!data) {
                        return;
                    }
                    $scope.tabFlag.type = 1;
                    $scope.changeTab(2);
                    $scope.orderObj = data;
                    angular.forEach($scope.orderObj.materialList, function (item) {
                        item.deliveryNum = item.deliveryNum - item.qty;
                    });
                });
            };

            $scope.checkStock = function (item) {
                item.qtyErr = false;
                if (!item.qty || parseFloat(item.qty) <= 0) {
                    item.qtyErr = true;
                    item.qtyErrMsgTxt = "出库数量不能为空和0";
                    return;
                }
                if (item.qty > 9999999.999) {
                    item.qty = 9999999.999;
                }
                if (parseFloat(item.qty) < parseFloat(item.realQty)) {
                    item.qtyErr = true;
                    item.qtyErrMsgTxt = "出库数量不能小于实际出库数量";
                    return;
                }
                item.outPrice = $filter("decimalCover")(ybWidget.Times(item.realQty, item.price), 2);
                item.totalPrice = $filter("decimalCover")(ybWidget.Times(item.qty, item.price), 2);
                item.costSubtotal = $filter("decimalCover")(ybWidget.Times(item.qty, item.costPrice), 2);
                checkItemStockStatus(item, +item.qty);
                setTotal();
            };

            function checkItemStockStatus(item, currentQty) {
                UserContextService.SetStockStatusFlag(item, currentQty);
            }

            function checkItemStockStatusForSubmit(item, currentQty) {
                if ($scope.isWJ || $scope.isNJ) {
                    //只有挖机才进行判断
                    UserContextService.SetStockStatusFlag(item, currentQty);
                }
            }

            $scope.showQtyTip = function (item) {
                if (!!item.qtyStockErr) {
                    item.showStockErr = true;
                }
            };
            $scope.hideQtyTip = function (item) {
                item.showStockErr = false;
            };
            $scope.printBill = function (item) {
                var id = item.id;
                var billIds = [];
                billIds.push(id);
                var param = {
                    billId: billIds,
                    printType: "UnusualOut"
                };
                ybWidget.SetIsPrintOrPreview(param);
            };
//   add by lf 批量打印
            $scope.batchPrint = function () {
                var billIds = [];
                for (var i = 0, len = $scope.dataList.length; i < len; i++) {
                    if (!!$scope.dataList[i].isChecked) {
                        billIds.push($scope.dataList[i].id);
                    }
                }
                if (billIds.length === 0) {
                    ybWidget.ShowMessage('请选择需要打印的行');
                    return;
                }

                var param = {
                    cusParam: { billIds },
                    cusInterface: '/abnormalOut/batchPrintInfo',
                    printType: "UnusualOut",
                    isBatchPrint: true,
                };
                ybWidget.SetIsPrintOrPreview(param).then(function() {
                    getDataList();
                });
            };

//end
            function checkListValid() {
                var isValid = true;
                for (var i = 0, len = $scope.orderObj.materialList.length; i < len; i++) {
                    if (!$scope.orderObj.materialList[i].qty || parseFloat($scope.orderObj.materialList[i].qty) <= 0) {
                        isValid = false;
                        $scope.orderObj.materialList[i].qtyErr = true;
                        $scope.orderObj.materialList[i].qtyErrMsg = "出库数量不能为空和0";
                        break;
                    }
                    if ($scope.tabFlag.type === 1 && (parseInt($scope.orderObj.materialList[i].qty) < parseInt($scope.orderObj.materialList[i].realQty))) {
                        isValid = false;
                        $scope.orderObj.materialList[i].qtyErr = true;
                        $scope.orderObj.materialList[i].qtyErrMsg = "出库数量不能小于实际出库数量";
                        break;
                    }

                    // if (!$scope.orderObj.materialList[i].price || parseFloat($scope.orderObj.materialList[i].price) <= 0) {
                    //     isValid = false;
                    //     $scope.orderObj.materialList[i].priceErr = true;
                    //     $scope.orderObj.materialList[i].priceErrMsgTxt = "单价不能为空和0";
                    //     break;
                    // }
                }
                return isValid;
            }

            $scope.saveData = function (isValid) {
                if (!isValid) {
                    $scope.submitted = true;
                    return;
                }
                if ($scope.orderObj.materialList.length === 0) {
                    ybWidget.ShowToaster('error', '零件不可为空');
                    return;
                }
                var listValid = checkListValid();
                if (!listValid) {
                    return;
                }
                if (isErrorStockStatusForExcavatorCompany()) {
                    return;
                }
                var service = "device";
                var reqUrl = "/abnormalOut/add";
                if ($scope.tabFlag.type === 1) {
                    reqUrl = "/abnormalOut/update";
                }
                var param = angular.copy($scope.orderObj);
                if (!!$scope.innerOrder.item) {
                    param.headerInfo.innerOrder = $scope.innerOrder.item.innerOrder;
                    param.headerInfo.innerOrderNote = $scope.innerOrder.item.innerOrderNote;
                } else {
                    param.headerInfo.innerOrder = "";
                    param.headerInfo.innerOrderNote = "";
                }
                ybHttp.Post(service, reqUrl, param).then(function (resp) {
                    if (resp.code !== 0) {
                        ybWidget.ShowMessage(resp, MESG_TYPE.Error);
                        return;
                    }
                    ybWidget.ShowToaster('success', '操作成功');
                    if ($scope.tabFlag.type === 0) {
                        getDataList(1);
                    } else {
                        getDataList();
                    }
                    $scope.changeTab(0);
                });
            };

            function isErrorStockStatusForExcavatorCompany() {
                if (!$scope.isWJ && !UserContextService.NeedCheckStockQty('其他出库', $scope.curOrgId)) {
                    return false;
                }
                for (var i = 0; i < $scope.orderObj.materialList.length; i++) {
                    checkItemStockStatusForSubmit($scope.orderObj.materialList[i], $scope.orderObj.materialList[i].qty);
                    // wangcan:库存校验
                    if (!$scope.btnPermission.unusualOutTJSC) {
                        if ($scope.orderObj.materialList[i].qtyStockErr && ($scope.orderObj.materialList[i].qtyStockErrLevel > 1)) {
                            ybWidget.ShowMessage("零件" + $scope.orderObj.materialList[i].materialsNo + "，" + $scope.orderObj.materialList[i].materialsDes + "库存不足，单据不能创建，请先删除该零件或取消提交", MESG_TYPE.Error);
                            $scope.clickValue = false;
                            return true;
                        }
                    }
                }
                return false;
            }

            $scope.outbound = function (item) {
                //基础需求
                if($scope.isJCH&&item.auditStatus!=1){
                    ybWidget.ShowMessage('未审核，不允许出库！', MESG_TYPE.Error, { title: '提醒' })
                }else{
                    getDetail(item.id).then(function (data) {
                        if (!data) {
                            return;
                        }
                        // wangcan:出库有多个库存储位时，默认展示第一个
                        angular.forEach(data.materialList, function (item) {
                            if (item.locationCode && item.locationCode.indexOf(',') != -1) {
                                var tempArr = item.locationCode.split(',');
                                item.locationCode = tempArr[0];
                            }
                        });
                        $scope.orderObj = data;
                        angular.forEach($scope.orderObj.materialList, function (item) {
                            item.statusShow = $filter("ProgressStatus")(item.status, "outDepot");
                        });
                        $scope.changeTab(4);
                    });
                }

            };

            $scope.selDepot = function (item) {
                var param = {
                    warehouseCode: $scope.orderObj.headerInfo.outLocation
                };
                ybWidget.DepotSelector(param).then(function (data) {
                    item.warehouseCode = data.warehouseCode;
                    item.areaCode = data.areaCode;
                    item.locationCode = data.locationCode;
                })
            };

            $scope.clearDepot = function (item) {
                item.warehouseCode = "";
                item.areaCode = "";
                item.locationCode = "";
            };

            $scope.outboundSubmit = function () {
                var service = "device";
                var reqUrl = "/warehouseDeliveryRecord/receive";
                var param = {
                    headerInfo: {},
                    detailList: []
                };
                var errorCount = 0;
                param.headerInfo.businessOrder = $scope.orderObj.headerInfo.abnormalNo;
                angular.forEach($scope.orderObj.materialList, function (item) {
                    var listRow = {};
                    listRow.materialNo = item.materialsNo;
                    listRow.warehouseCode = item.warehouseCode;
                    listRow.areaCode = item.areaCode;
                    listRow.locationCode = item.locationCode;
                    item.locationErr = false;
                    if ((item.status === 0 || item.status === 1) && !item.locationCode) {
                        item.locationErr = true;
                        errorCount++;
                    }
                    param.detailList.push(listRow);
                });
                if (errorCount > 0) {
                    return;
                }
                ybHttp.Post(service, reqUrl, param).then(function (resp) {
                    if (resp.code !== 0) {
                        ybWidget.ShowMessage(resp, MESG_TYPE.Error);
                        return;
                    }
                    ybWidget.ShowToaster('success', '操作成功');
                    $scope.changeTab(0);
                    getDataList();
                });
            };

            $scope.cancel = function () {
                $scope.changeTab(0);
            };

            $scope.obligate = function (item) {
                item.obligateDisabled = true;
                var service = "device";
                var reqUrl = "/warehouseInventory/createObligateOrder";
                var param = {};
                param.id = item.id;
                param.businessOrder = item.abnormalNo;
                ybHttp.Post(service, reqUrl, param).then(function (resp) {
                    if (resp.code !== 0) {
                        ybWidget.ShowMessage(resp, MESG_TYPE.Error);
                        item.obligateDisabled = false;
                        return;
                    }
                    ybWidget.ShowToaster('success', '操作成功');
                    getDataList();
                });
            };

            $scope.posting = function (item, materialsNo) {
                ybWidget.ShowMessage("确定要过账吗？", MESG_TYPE.Ask).then(function () {
                    item.postingDisabled = true;
                    var service = "device";
                    var reqUrl = "/warehouseInventory/obligatePosting";
                    var param = {};
                    param.businessOrder = item.abnormalNo;
                    param.materialsNo = materialsNo;
                    ybHttp.Post(service, reqUrl, param).then(function (resp) {
                        if (resp.code !== 0) {
                            ybWidget.ShowMessage(resp, MESG_TYPE.Error);
                            item.postingDisabled = false;
                            return;
                        }
                        ybWidget.ShowToaster('success', '操作成功');
                        if (!!item.id) {
                            getDetail(item.id).then(function (data) {
                                if (!data) {
                                    return;
                                }
                                $scope.orderObj = data;
                            });
                        }
                        getDataList();
                    });
                }, function () {});
            };

            $scope.deliveryRevoke = function (item, materialsNo) {
                ybWidget.ShowMessage("确定要撤回吗？", MESG_TYPE.Ask).then(function () {
                    var service = "device";
                    var reqUrl = "/warehouseInventory/deliveryRevoke";
                    var param = {
                        businessOrder: item.abnormalNo,
                        materialsNo: materialsNo ? materialsNo : null
                    };
                    ybHttp.Post(service, reqUrl, param).then(function (resp) {
                        if (resp.code !== 0) {
                            ybWidget.ShowMessage(resp, MESG_TYPE.Error);
                            return;
                        }
                        ybWidget.ShowToaster('success', '操作成功');
                        if (!!item.id) {
                            getDetail(item.id).then(function (data) {
                                if (!data) {
                                    return;
                                }
                                $scope.orderObj = data;
                            });
                        }
                        getDataList();
                    });
                }, function () {});
            };

            $scope.mandatoryFinish = function (billNo, billId, materialsNo) {
                ybWidget.ShowMessage("确定要结单吗？", MESG_TYPE.Ask).then(function () {
                    var service = "device";
                    var reqUrl = "/abnormalOut/manualFinish";
                    var param = {
                        billNo: billNo,
                        materialsNo: materialsNo ? materialsNo : null
                    };
                    ybHttp.Post(service, reqUrl, param).then(function (resp) {
                        if (resp.code !== 0) {
                            ybWidget.ShowMessage(resp, MESG_TYPE.Error);
                            return;
                        }
                        ybWidget.ShowToaster('success', '操作成功');
                        if (!!billId) {
                            getDetail(billId).then(function (data) {
                                if (!data) {
                                    return;
                                }
                                $scope.orderObj = data;
                            });
                        }
                        getDataList();
                    });
                }, function () {});
            };

            $scope.auditBill = function (item) {
                $scope.auditMessage = {};
                $scope.auditId = item.id;
                getDetail(item.id).then(function (data) {
                    if (!data) {
                        return;
                    }
                    $scope.changeTab(5);
                    $scope.orderObj = data;
                    angular.forEach($scope.orderObj.materialList, function (item) {
                        item.deliveryNum = item.deliveryNum - item.qty;
                    });
                });
            };

            $scope.auditMessage = {};
            $scope.handleAudit = function(type, ids, msg) {
                var service = "device";
                var reqUrl = "";
                var param = {
                    ids: ids || [$scope.auditId]
                };

                var msgStr = msg || $scope.auditMessage.value;
                if (type == 1) {
                    // 通过
                    reqUrl = "/abnormalOut/auditPass"
                } else if (type == 2) {
                    // 拒绝
                    if (!msgStr) {
                        ybWidget.ShowMessage("请填写审核意见", MESG_TYPE.Error);
                        return
                    }
                    reqUrl = "/abnormalOut/auditReject"
                }
                param.auditRemark = msgStr;

                return ybHttp.Post(service, reqUrl, param).then(function (resp) {
                    if (resp.code !== 0) {
                        ybWidget.ShowMessage(resp, MESG_TYPE.Error);
                        return;
                    }
                    ybWidget.ShowToaster('success', '操作成功');
                    getDataList();
                    $scope.changeTab(0);
                });
            };

            $scope.auditData = function () {
                $scope.auditMessage = {};
                var ids = [];
                for (var i = 0, len = $scope.dataList.length; i < len; i++) {
                    if (!!$scope.dataList[i].isChecked) {
                        ids.push($scope.dataList[i].id);
                    }
                }
                if (ids.length === 0) {
                    ybWidget.ShowMessage('请正确选择需要审核的行');
                    return;
                }
                ybWidget.AuditMsg({
                    passCb: function(val) {
                        return $scope.handleAudit (1, ids, val)
                    },
                    refuseCb: function(val) {
                        return $scope.handleAudit (2, ids, val)
                    }
                })
            };


            EventBus.Subscribe("onMaterialChange", setTotal);

            function setTotal() {
                var totalPrice = 0;
                var costTotal = 0;
                angular.forEach($scope.orderObj.materialList, function (item) {
                    item.totalPrice = $filter("decimalCover")(ybWidget.Times(item.qty, item.price), 2);
                    totalPrice = ybWidget.Plus(totalPrice, parseFloat(item.totalPrice));
                    costTotal = ybWidget.Plus(costTotal, parseFloat(item.costSubtotal));
                });
                $scope.orderObj.headerInfo.totalAmount = totalPrice;
                $scope.orderObj.headerInfo.costTotal = costTotal;
            }

            $scope.batchPosting = function() {
                const conditionList = $scope.dataList.filter(df => df.isChecked).map(dm => {
                    return {
                        businessOrder: dm.abnormalNo,
                        inOut: 1,
                    }
                })

                if (conditionList.length === 0) {
                    ybWidget.ShowMessage('请选择需要操作的行');
                    return;
                }

                ybWidget.ShowMessage("确定要批量过账吗？", MESG_TYPE.Ask).then(function () {
                    ybHttp.Post('device', '/warehouseInventory/obligatePostingBatch', conditionList).then(function (resp) {
                        if (resp.code !== 0) {
                            ybWidget.ShowMessage(resp, MESG_TYPE.Error);
                            return;
                        }
                        ybWidget.ShowToaster('success', '操作成功');
                        getDataList();
                    });
                });
            };

            $scope.batchReserve = function() {
                const conditionList = $scope.dataList.filter(df => df.isChecked).map(dm => {
                    return {
                        businessOrder: dm.abnormalNo,
                        id: dm.id,
                    }
                })

                if (conditionList.length === 0) {
                    ybWidget.ShowMessage('请选择需要操作的行');
                    return;
                }

                ybWidget.ShowMessage("确定要批量创建预留吗？", MESG_TYPE.Ask).then(function () {
                    ybHttp.Post('device', '/warehouseInventory/createObligateOrderBatch', conditionList).then(function (resp) {
                        if (resp.code !== 0) {
                            ybWidget.ShowMessage(resp, MESG_TYPE.Error);
                            return;
                        }
                        ybWidget.ShowToaster('success', '操作成功');
                        getDataList();
                    });
                });
            };

            $scope.handleReceipt = function (billId) {
                var service = "device";
                var reqUrl = "/abnormalOut/receiptConfirm";

                ybWidget.ShowMessage("确定回执吗？", MESG_TYPE.Ask).then(function () {
                    ybHttp.Post(service, reqUrl, { id: billId }).then(function (resp) {
                        if (resp.code !== 0) {
                            ybWidget.ShowMessage(resp, MESG_TYPE.Error);
                            return;
                        }
                        ybWidget.ShowToaster('success', '操作成功');
                        getDataList();
                    });
                });
            };

            $scope.sync2Car = function(billId) {
                var service = "device";
                var reqUrl = "/abnormalOut/syncFleetManagementSystem";
                ybHttp.Post(service, reqUrl, { id: billId }).then(function (resp) {
                    if (resp.code !== 0) {
                        ybWidget.ShowMessage(resp, MESG_TYPE.Error);
                        return;
                    }
                    ybWidget.ShowToaster('success', '操作成功');
                    getDataList();
                });
            };

            $scope.selectSupplier = function () {
                var param = {
                    name: "供货商",
                    type: "supplier",
                    isPlat: true
                };
                ybWidget.SingleSelector(param).then(function (data) {
                    $scope.orderObj.headerInfo.supplierOrgId = data.platOrgId;
                    $scope.orderObj.headerInfo.supplierOrgName = data.companyName;
                })
            };

            $scope.clearSupplier = function () {
                $scope.orderObj.headerInfo.supplierOrgId = "";
                $scope.orderObj.headerInfo.supplierOrgName = "";
            };

            (function () {
                $scope.isKY = ['815898577741021184', '1050703644351004672'].includes($scope.curOrgId); // 徐州徐工矿业工程有限公司
                if ($scope.isKY) {
                    const tabCols = $scope.tbConf.tableCol;
                    const extraCols = [
                        {
                            name: "同步车队系统状态",
                            dataField: "syncCdglxtStatusShow",
                            width: 140,
                            isShow: true,
                            isFixed: false,
                        },
                        {
                            name: "同步车队系统时间",
                            dataField: "syncCdglxtTimeShow",
                            width: 140,
                            isShow: true,
                            isFixed: false,
                        },
                        {
                            name: "同步车队系统信息",
                            dataField: "syncCdglxtMsg",
                            width: 140,
                            isShow: true,
                            isFixed: false,
                        },
                    ];
                    $scope.tbConf.tableCol = tabCols.concat(extraCols);
                }

                var unusualOutBillNo = window.sessionStorage.getItem("unusualOutBillNo");
                window.sessionStorage.removeItem("unusualOutBillNo");
                if (!!unusualOutBillNo) {
                    $scope.condition.abnormalNo = unusualOutBillNo;
                    getDataList().then(function (data) {
                        viewDetail(data[0]);
                    })
                } else {
                    $scope.condition.dept = $scope.isJCH ? $scope.curUser.deptName : undefined;
                    getDataList();
                }
                getReason();
                getTypeList();
                $scope.setFixedWidth();
                UserContextService.SetBtnPermission(setBtnPermission);
            })();
        }]);
})(window, window.angular);
